import { request } from '@/utils/request'
import type { CartItem } from '@/types/cart'

// 加入购物车参数类型
type CartParams = {
  // 商品数量
  count: number
  // 商品skuId
  skuId: string
}
// 加入购物车
export function postMemberCart(data: CartParams) {
  return request({
    url: '/member/cart',
    method: 'POST',
    data,
  })
}

// 获取购物车列表
export function getMemberCart() {
  return request<CartItem[]>({
    url: '/member/cart',
  })
}

// 删除购物车商品
export function deleteMemberCart(ids: string[]) {
  return request({
    url: `/member/cart/`,
    method: 'DELETE',
    data: {
      ids,
    },
  })
}

// 修改购物车商品数量
export const putMemberCartBySkuIdAPI = (
  skuId: string,
  data: { selected?: boolean; count?: number },
) => {
  return request({
    method: 'PUT',
    url: `/member/cart/${skuId}`,
    data,
  })
}

// 修改购物车商品全选
export function putMemberCartSelected(selected: boolean) {
  return request({
    url: `/member/cart/selected`,
    method: 'PUT',
    data: {
      selected,
    },
  })
}
